**************Plotting moments fit***************
//Fuyao Wang
//6.7.2021

clear all
set more off, perm
capture log close
set maxvar 32767
global klmChinaReach2: env klmChinaReach2
global datapath "${klmChinaReach2}/Fuyao_Erlfang"
cd "$datapath\moments_dta"



******all task passing rate 195******

use alltask_rate_195, clear
// merge 1:1 ts_id using "$datapath/Eleanor/Control Groups/controlgroup.dta", nogen keepusing(level* repeat*)


unab skills : level*
local skills : subinstr local skills "level" "", all
foreach skill of local skills {
	sort level`skill' ts_id
	replace level`skill' = . if level`skill' == -99
	gen index`skill'= sum(!missing(level`skill')) if !missing(level`skill')
}
sort indext

**Paste over lines 1-195 simulated moments - var16

replace var16 = . if var16 == -99

label var mean_task "Data"
label var ub "95% CI"
label var var16 "Model"



unab skills : level*
local skills : subinstr local skills "level" "", all
foreach skill of local skills {
	local xlines ""
	local xlabels ""
	sum level`skill'
	if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index`skill' if level`skill'==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
	sort index`skill'
	if inlist("`skill'","f2")==1 {
	twoway line mean_task index`skill', sort lwidth(medthin) || line ub index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var16 index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks by Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/fine_alltask", replace)
	graph export "plots/1982moments/fine_alltask.pdf", replace	
	}
	else if inlist("`skill'","l")==1 {
	twoway line mean_task index`skill', sort lwidth(medthin) || line ub index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var16 index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks by Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/lan_alltask", replace)
	graph export "plots/1982moments/lan_alltask.pdf", replace	
	}
	else if inlist("`skill'","c2")==1 {
	twoway line mean_task index`skill', sort lwidth(medthin) || line ub index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var16 index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks by Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/cog_alltask", replace)
	graph export "plots/1982moments/cog_alltask.pdf", replace	
	}
	else if inlist("`skill'","g")==1{
	twoway line mean_task index`skill', sort lwidth(medthin) || line ub index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var16 index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks by Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/gross_alltask", replace)
	graph export "plots/1982moments/gross_alltask.pdf", replace	
	}
	}
}



********************************196-731 for language*********************************
	
******levell only 11******
use levell_rate, clear


label var mean_task "Data"
label var ub "95% CI"
**paste over 196-206
label var var7 "Model"

twoway line mean_task levell, sort lwidth(medthin) || line ub levell, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb levell, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var7 levell, sort msize(small)   ///
	xlabel(1(1)11, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks Average Passing Rate at Each Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/lan_levell", replace)
	graph export "plots/1982moments/lan_levell.pdf", replace	


******Conditional on previous level******


use artl_rate_pre1, clear

**Paste over lines 207-431 simulated moments - var9

// gen temp = _n
gen indexl = mod(_n, 25)
replace indexl = 25 if indexl == 0

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"
forval i = 3/11{
	twoway line mean indexl if l_focus == `i', sort lwidth(medthin) || line ub indexl if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexl if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexl if l_focus == `i', sort msize(small)   ///
	xline(5(5)20, lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(1 5(5)25, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks Average Passing Rate (Level `i')", size(medium)) subtitle("Conditional on Difficulty Level `=`i'-1' Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Index 1-5 represents the first 5 tasks at difficulty level `i' conditional on the passing the first task at level `=`i'-1'." "Index 6-10 represents the first 5 tasks at difficulty level `i' conditional on the passing the second task at level `=`i'-1'." "Similarly, index 11-15, 16-20, 20-25 represent that conditional on passing the 3rd, 4th, and 5th task at level `=`i'-1', respectively." "2. The dashed yellow lines indicate the last task of each index group.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/lan_pre1_l`i'", replace)
	graph export "plots/1982moments/lan_pre1_l`i'.pdf", replace	

}


******Conditional on previous task************

use artl_rate_pretask, clear
**Paste over lines 432-531 simulated moments - var9
gen indexl = _n

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"
replace var9 = . if var9 == -99
local xlabels ""
forval i = 2/11{
	local k = 10*(`i'-1)
	local xlabels "`xlabels' `k' "`i'" "
}

twoway line mean indexl, sort lwidth(medthin) || line ub indexl, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexl, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexl, sort msize(small)   ///
	xline(10(10)100, lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks Average Passing Rate", size(medium)) subtitle(Conditional on Previous Tasks' Performance at the Same Level, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The figure presents the average passing rate for each task conditional on passing previous tasks at each level. For example, it shows tasks" "2-5's passing rates conditional on passing the first tasks, and tasks 3-5's passing rates conditional on passing task 2, etc., at each difficulty level." "2. The dashed yellow lines indicate the last task at each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/lan_pretask", replace)
	graph export "plots/1982moments/lan_pretask.pdf", replace	



******Conditional on previous 2 level******

use artl_rate_pre2, clear

**Paste over lines 532-731 simulated moments - var9

replace var9 = . if var9 == -99
gen indexl = mod(_n, 25)
replace indexl = 25 if indexl == 0

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"
forval i = 4/11{
	twoway line mean indexl if l_focus == `i', sort lwidth(medthin) || line ub indexl if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexl if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexl if l_focus == `i', sort msize(small)   ///
	xline(5(5)20, lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(1 5(5)25, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks Average Passing Rate (Level `i')", size(medium)) subtitle("Conditional on Difficulty Level `=`i'-2' Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Index 1-5 represents the first 5 tasks at difficulty level `i' conditional on the passing the first task at level `=`i'-2'." "Index 6-10 represents the first 5 tasks at difficulty level `i' conditional on the passing the second task at level `=`i'-2'." "Similarly, index 11-15, 16-20, 20-25 represent that conditional on passing the 3rd, 4th, and 5th task at level `=`i'-2', respectively." "2. The dashed yellow lines indicate the last task of each index group.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/lan_pre2_l`i'", replace)
	graph export "plots/1982moments/lan_pre2_l`i'.pdf", replace	

}



*******************************************New and old group***************************************
/*
use enroll_1mo_195, clear
sort indext

**Paste over lines 732-926 simulated moments for new enroll - var41
**Paste over lines 927-1121 simulated moments for old enroll - var42
rename var41 sim_new
rename var42 sim_old

replace sim_new = . if sim_new == -99
replace sim_old = . if sim_old == -99

keep if N_old>10 & N_new>10

unab skills : level*
local skills : subinstr local skills "level" "", all
foreach skill of local skills {
	sort level`skill' ts_id
	replace level`skill' = . if level`skill' == -99
	gen index`skill'= sum(!missing(level`skill')) if !missing(level`skill')
}
unab skills : level*
local skills : subinstr local skills "level" "*", all
order `skills', after(max_age)
sort indext


label var mean_new "Data"
label var ub_new "95% CI"
label var sim_new "Model"
label var mean_old "Data"
label var ub_old "95% CI"
label var sim_old "Model"

preserve
drop if mean_new == .


unab skills : level*
local skills : subinstr local skills "level" "", all
foreach skill of local skills {
	local xlines ""
	local xlabels ""
	sum level`skill'
	if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index`skill' if level`skill'==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
	sort index`skill'
	if inlist("`skill'","f2")==1 {
	twoway line mean_new index`skill', sort lwidth(medthin) || line ub_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_new index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks for Newly Enrolled Group", size(medium)) subtitle(Enrollment Duration Less than One Month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled < 1 Month represents children who had been in the program for less than one month when the task was evaluated." "2. Tasks with fewer than 10 observations in either group are omitted.   3. The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/fine_groupnew", replace)
	graph export "plots/1982moments/fine_groupnew.pdf", replace	
	}
	else if inlist("`skill'","l")==1 {
	twoway line mean_new index`skill', sort lwidth(medthin) || line ub_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_new index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks for Newly Enrolled Group", size(medium)) subtitle(Enrollment Duration Less than One Month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled < 1 Month represents children who had been in the program for less than one month when the task was evaluated." "2. Tasks with fewer than 10 observations in either group are omitted.   3. The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/lan_groupnew", replace)
	graph export "plots/1982moments/lan_groupnew.pdf", replace	
	}
	else if inlist("`skill'","c2")==1 {
	twoway line mean_new index`skill', sort lwidth(medthin) || line ub_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_new index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks for Newly Enrolled Group", size(medium)) subtitle(Enrollment Duration Less than One Month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled < 1 Month represents children who had been in the program for less than one month when the task was evaluated." "2. Tasks with fewer than 10 observations in either group are omitted.   3. The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/cog_groupnew", replace)
	graph export "plots/1982moments/cog_groupnew.pdf", replace	
	}
	else if inlist("`skill'","g")==1{
	twoway line mean_new index`skill', sort lwidth(medthin) || line ub_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_new index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_new index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks for Newly Enrolled Group", size(medium)) subtitle(Enrollment Duration Less than One Month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled < 1 Month represents children who had been in the program for less than one month when the task was evaluated." "2. Tasks with fewer than 10 observations in either group are omitted.   3. The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/gross_groupnew", replace)
	graph export "plots/1982moments/gross_groupnew.pdf", replace	
	}
	}
}

restore



preserve
drop if mean_old == .


unab skills : level*
local skills : subinstr local skills "level" "", all
foreach skill of local skills {
	local xlines ""
	local xlabels ""
	sum level`skill'
	if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index`skill' if level`skill'==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
	sort index`skill'
	if inlist("`skill'","f2")==1 {
	twoway line mean_old index`skill', sort lwidth(medthin) || line ub_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_old index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks for for Already Enrolled Group", size(medium)) subtitle(Enrollment Duration More than one month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled > 1 Month represents children who had been in the program for more than one month when the task was evaluated, who continued" "to stay in the program for 2 years. 2. Tasks with fewer than 10 observations in either group are omitted.  3. The dashed yellow lines indicate" "the last task at each difficulty level. Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/fine_groupold", replace)
	graph export "plots/1982moments/fine_groupold.pdf", replace	
	}
	else if inlist("`skill'","l")==1 {
	twoway line mean_old index`skill', sort lwidth(medthin) || line ub_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_old index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks for for Already Enrolled Group", size(medium)) subtitle(Enrollment Duration More than one month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled > 1 Month represents children who had been in the program for more than one month when the task was evaluated, who continued" "to stay in the program for 2 years. 2. Tasks with fewer than 10 observations in either group are omitted.  3. The dashed yellow lines indicate" "the last task at each difficulty level. Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/lan_groupold", replace)
	graph export "plots/1982moments/lan_groupold.pdf", replace	
	}
	else if inlist("`skill'","c2")==1 {
	twoway line mean_old index`skill', sort lwidth(medthin) || line ub_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_old index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks for for Already Enrolled Group", size(medium)) subtitle(Enrollment Duration More than one month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled > 1 Month represents children who had been in the program for more than one month when the task was evaluated, who continued" "to stay in the program for 2 years. 2. Tasks with fewer than 10 observations in either group are omitted.  3. The dashed yellow lines indicate" "the last task at each difficulty level. Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/cog_groupold", replace)
	graph export "plots/1982moments/cog_groupold.pdf", replace	
	}
	else if inlist("`skill'","g")==1{
	twoway line mean_old index`skill', sort lwidth(medthin) || line ub_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb_old index`skill', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter sim_old index`skill', sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks for for Already Enrolled Group", size(medium)) subtitle(Enrollment Duration More than one month, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled > 1 Month represents children who had been in the program for more than one month when the task was evaluated, who continued" "to stay in the program for 2 years. 2. Tasks with fewer than 10 observations in either group are omitted.  3. The dashed yellow lines indicate" "the last task at each difficulty level. Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/gross_groupold", replace)
	graph export "plots/1982moments/gross_groupold.pdf", replace	
	}
	}
}

restore
*/


*******************************************c2 f2 g one number/level***************************************
/*
******levelc2 only 13******
use levelc2_rate, clear


label var mean_task "Data"
label var ub "95% CI"
**paste over 1122-1134
label var var7 "Model"

twoway line mean_task levelc2, sort lwidth(medthin) || line ub levelc2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb levelc2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var7 levelc2, sort msize(small)   ///
	xlabel(1(1)13, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks Average Passing Rate at Each Level", size(medium)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/cog_levelc2", replace)
	graph export "plots/1982moments/cog_levelc2.pdf", replace	


******levelf2 only 7******
use levelf2_rate, clear


label var mean_task "Data"
label var ub "95% CI"
**paste over 1135-1141
label var var7 "Model"

twoway line mean_task levelf2, sort lwidth(medthin) || line ub levelf2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb levelf2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var7 levelf2, sort msize(small)   ///
	xlabel(1(1)7, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks Average Passing Rate at Each Level", size(medium)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/fine_levelf2", replace)
	graph export "plots/1982moments/fine_levelf2.pdf", replace	
	
	
******levelg only 9******
use levelg_rate, clear


label var mean_task "Data"
label var ub "95% CI"
**paste over 1142-1150
label var var7 "Model"
drop if levelg == 1
twoway line mean_task levelg, sort lwidth(medthin) || line ub levelg, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb levelg, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var7 levelg, sort msize(small)   ///
	xlabel(2(1)9, labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks Average Passing Rate at Each Level", size(medium)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/gross_levelg", replace)
	graph export "plots/1982moments/gross_levelg.pdf", replace	
*/

	
	
*******************************************c2 f2 g conditional on previous level***************************************
/*
use artc2_rate_pre1, clear

**Paste over lines 1151-1327 simulated moments - var9

gen temp = _n

bys l_focus (temp): gen indexc2 = _n

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"
forval i = 2/12{
	sum indexc2 if l_focus == `i'
	if `r(max)' <= 16 & `r(max)' > 10 {
		local xlabels "1(2)`r(max)'"
	}
	else if `r(max)' <= 10 {
		local xlabels "1(1)`r(max)'"
	}
	else if `r(max)' > 16 {
		local xlabels "1 5(5)`r(max)'"
	}
	twoway line mean indexc2 if l_focus == `i', sort lwidth(medthin) || line ub indexc2 if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexc2 if l_focus == `i', sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexc2 if l_focus == `i', sort msize(small)   ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks Conditional on Pervious Difficulty Level", size(medium)) subtitle(Difficulty Level `i', size(small)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. Enrolled < 1 Month represents children who had been in the program for less than one month when the task was evaluated." "2. Enrolled > 1 Month represents children who had been in the program for more than one month when the task was evaluated, who continued" "to stay in the program for 2 years."  "The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/cog_pre1_l`i'", replace)
	graph export "plots/1982moments/cog_pre1_l`i'.pdf", replace	

}	




use artf2_rate_pre1, clear

**Paste over lines 1328-1411 simulated moments - var9

gen indexf2 = _n


label var mean "Data"
label var ub "95% CI"
label var var9 "Model"


local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexg if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}
	twoway line mean indexf2, sort lwidth(medthin) || line ub indexf2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexf2, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexf2, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///	
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks Average Passing Rate", size(medium)) subtitle("Conditional on the Previous Difficulty Level Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/fine_pre1", replace)
	graph export "plots/1982moments/fine_pre1.pdf", replace	

	



use artg_rate_pre1, clear

**Paste over lines 1412-1442 simulated moments - var9

gen indexg = _n
replace var9 = . if var9 == -99

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"


local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum indexg if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean indexg, sort lwidth(medthin) || line ub indexg, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexg, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexg, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///	
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks Average Passing Rate", size(medium)) subtitle("Conditional on the Previous Difficulty Level Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("The dashed yellow lines indicate the last task at each difficulty level." "Within difficulty levels, tasks are arranged by order of the children taking them.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/gross_pre1", replace)
	graph export "plots/1982moments/gross_pre1.pdf", replace	
*/

*******************************************c2 f2 g conditional on previous task***************************************


use artc2_rate_pretask, clear
**Paste over lines 1443-1524 simulated moments - var9
gen index = _n
replace var9 = . if var9 == -99

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"

local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}


twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///	
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks Average Passing Rate", size(medium)) subtitle(Conditional on Previous Tasks' Performance at the Same Level, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The figure presents the average passing rate for each task conditional on passing previous tasks at each level. For example, it shows tasks" "2-5's passing rates conditional on passing the first tasks, and tasks 3-5's passing rates conditional on passing task 2, etc., at each difficulty level." "2. The dashed yellow lines indicate the last task at each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/cog_pretask", replace)
	graph export "plots/1982moments/cog_pretask.pdf", replace	




use artf2_rate_pretask, clear
**Paste over lines 1525-1567 simulated moments - var9
gen index = _n
replace var9 = . if var9 == -99

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"

local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}


twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///	
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks Average Passing Rate", size(medium)) subtitle(Conditional on Previous Tasks' Performance at the Same Level, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The figure presents the average passing rate for each task conditional on passing previous tasks at each level. For example, it shows tasks" "2-5's passing rates conditional on passing the first tasks, and tasks 3-5's passing rates conditional on passing task 2, etc., at each difficulty level." "2. The dashed yellow lines indicate the last task at each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/fine_pretask", replace)
	graph export "plots/1982moments/fine_pretask.pdf", replace	

	

use artg_rate_pretask, clear
**Paste over lines 1568-1579 simulated moments - var9
gen index = _n
replace var9 = . if var9 == -99

label var mean "Data"
label var ub "95% CI"
label var var9 "Model"
replace var9 = . if var9 == -99
local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}


twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///	
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks Average Passing Rate", size(medium)) subtitle(Conditional on Previous Tasks' Performance at the Same Level, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The figure presents the average passing rate for each task conditional on passing previous tasks at each level. For example, it shows tasks" "2-5's passing rates conditional on passing the first tasks, and tasks 3-5's passing rates conditional on passing task 2, etc., at each difficulty level." "2. The dashed yellow lines indicate the last task at each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin)) ///
	saving("plots/1982moments/gross_pretask", replace)
	graph export "plots/1982moments/gross_pretask.pdf", replace	
	

	
	
	

*******************************************c2 f2 g conditional on previous 2 level***************************************

use artc2_rate_pre2, clear
**paste over 1580-1721 - var9

gen index = _n
replace var9 = . if var9 == -99


label var mean "Data"
label var ub "95% CI"
label var var9 "Model"


local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks Average Passing Rate", size(medium)) subtitle("Conditional on the Difficulty Level Two Steps Down Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The dashed yellow lines indicate the last task of each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/cog_pre2", replace)
	graph export "plots/1982moments/cog_pre2.pdf", replace	




use artf2_rate_pre2, clear

**paste over 1722-1800 - var9


gen index = _n
replace var9 = . if var9 == -99


label var mean "Data"
label var ub "95% CI"
label var var9 "Model"


local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks Average Passing Rate", size(medium)) subtitle("Conditional on the Difficulty Level Two Steps Down Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The dashed yellow lines indicate the last task of each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/fine_pre2", replace)
	graph export "plots/1982moments/fine_pre2.pdf", replace	
	

	

use artg_rate_pre2, clear

**paste over 1801-1824 - var9


gen index = _n
replace var9 = . if var9 == -99


label var mean "Data"
label var ub "95% CI"
label var var9 "Model"


local xlines ""
local xlabels ""
sum l_focus
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if l_focus==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks Average Passing Rate", size(medium)) subtitle("Conditional on the Difficulty Level Two Steps Down Task Performance", size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("1. The dashed yellow lines indicate the last task of each difficulty level.", size(vsmall) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/gross_pre2", replace)
	graph export "plots/1982moments/gross_pre2.pdf", replace		
	

	
	
*******************************************l c2 f2 g first 5 tasks each level***************************************

	
******artl1-5, level 2/11******
use artl1-5_rate, clear
gen indexl = _n

label var mean "Data"
label var ub "95% CI"

**paste 867-916 - var9
label var var9 "Model"
local xlabels ""
forval i = 2/11{
	local k = 5*(`i'-1)
	local xlabels "`xlabels' `k' "`i'" "
}

	twoway line mean indexl, sort lwidth(medthin) || line ub indexl, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb indexl, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var9 indexl, sort msize(small)   ///
	xline(5(5)50, lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Difficulty Level, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Language Tasks by Level", size(medium)) subtitle(First Five Tasks, size(small)) legend(order(1 2 4) row(1) size(small) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/lan_first5_alllevel", replace)
	graph export "plots/1982moments/lan_first5_alllevel.pdf", replace	
	
	

	
******artc21-5, level 1/12******
use artc21-5_rate, clear

**paste 1875-1934 - var8
label var var8 "Model"
drop if var8 == -99
gen index = _n

label var mean "Data"
label var ub "95% CI"


local xlines ""
local xlabels ""
sum level
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if level==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var8 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Cognitive Tasks by Level", size(medium)) subtitle(First Few Tasks at Each Level, size(small)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/cog_first5_alllevel", replace)
	graph export "plots/1982moments/cog_first5_alllevel.pdf", replace	
	

	
******artf21-5, level 1/6******
use artf21-5_rate, clear

**paste 1935-1964 - var8
label var var8 "Model"
drop if var8 == -99
gen index = _n

label var mean "Data"
label var ub "95% CI"


local xlines ""
local xlabels ""
sum level
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if level==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var8 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Fine Motor Tasks by Level", size(medium)) subtitle(First Few Tasks at Each Level, size(small)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/fine_first5_alllevel", replace)
	graph export "plots/1982moments/fine_first5_alllevel.pdf", replace	

	
	
******artg1-5, level 4/9******
use artg1-5_rate, clear

**paste 1965-1982 - var8
label var var8 "Model"
drop if var8 == -99
gen index = _n

label var mean "Data"
label var ub "95% CI"


local xlines ""
local xlabels ""
sum level
if r(N)>0 {
	forval level=`r(min)'/`r(max)' {
		sum index if level==`level'
		if r(N)>0 {
		local xlines "`xlines' `r(max)'"
		local xlabels `" `xlabels' `r(max)' "`level'" "'
		}
	}
}

	twoway line mean index, sort lwidth(medthin) || line ub index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || line lb index, sort lcolor(gs11) lpattern(dash) lwidth(medthin) || scatter var8 index, sort msize(small)   ///
	xline(`xlines', lcolor(khaki) lpattern(dash) lwidth(thin)) ///
	xlabel(`xlabels', labsize(small)) xmtick(, labsize(small)) ///
	xtitle(Moment Index, size(small)) ytitle(Passing Rate, size(small)) ylabel(,labsize(small)) ///
	title("Fit for Gross Motor Tasks by Level", size(medium)) subtitle(First Few Tasks at Each Level, size(small)) legend(order(1 2 4) row(1) size(vsmall) nobox fcolor() region(fcolor(white) margin(zero)) bmargin(zero) rowgap(tiny) colgap(tiny) keygap(tiny)) ///
	note("Note: The dashed yellow lines indicate the last task at each difficulty level. Within difficulty levels, " "tasks are arranged by order of the children taking them.", size(small) span) ///
	graphregion(fcolor(white) ifcolor(white) ilwidth(vvvthin)) plotregion(margin(medsmall) lwidth(vvvthin) ilwidth(vvvthin))  ///
	saving("plots/1982moments/gross_first5_alllevel", replace)
	graph export "plots/1982moments/gross_first5_alllevel.pdf", replace	


	

